<template>
	<view class="container">
		<view class="header common-header">余额：{{ account }}</view>
		<view class="input-container">
			<text class="title">充值金额</text>
			<input type="number" class="input" focus="true" v-model="balance" />
		</view>
		<button type="primary" class="btn" @tap="charge">充值</button>
	</view>
</template>

<script>
import { rechage } from '@/common/pay.js';
export default {
	data() {
		return {
			account: 0.0,
			agencyId: '',
			balance: 0
		};
	},
	onLoad(e) {
		this.agencyId = e.agencyId;
		this.$http
			.request({
				url: 'api/Agency/GetAgencyAccount',
				data: {
					agencyId: this.agencyId
				}
			})
			.then(res => {
				this.account = res;
				// #ifdef H5
				this.$wechat.share({
					link: this.$handlerAppMessagePath()
				});
				// #endif
			});
	},
	onShareAppMessage(e) {
		return {
			path: this.$handlerAppMessagePath()
		};
	},
	methods: {
		charge() {
			var that = this;
			// #ifdef MP-WEIXIN
			var paymentMethod = 1;
			// #endif
			// #ifdef H5
			var paymentMethod = 2;
			// #endif
			rechage({ agencyId: this.agencyId, balance: this.balance, paymentMethod: paymentMethod }, function() {
				that.account = this.account + this.balance;
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.input-container {
	.title {
		font-size: 35rpx;

		padding: 0 10px;
	}
	.input {
		font-size: 30rpx;
		flex-grow: 1;
		flex-shrink: 0;
	}
}
.btn {
	margin-top: 30px;
	background: #179b16;
}
</style>
